<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('违规记录列表')" />
</head>
<body class="gray-bg">
     <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="formId">
                    <div class="select-list">
                        <ul>
                            <li>
                                <label>奖罚类型：</label>
                                <select name="illegalTypeId" th:with="type=${@illegalType.getIllegalType()}">
                                    <option value="">全部</option>
                                    <option th:each="dict : ${type}" th:text="${dict.illegalTypeName}" th:value="${dict.id}"></option>
                                </select>
                            </li>

                            <li class="select-time">
                                <label>创建时间：</label>
                                <input type="text" class="time-input" id="startTime" placeholder="开始时间" name="params[beginTime]"/>
                                <span>-</span>
                                <input type="text" class="time-input" id="endTime" placeholder="结束时间" name="params[endTime]"/>
                            </li>
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>

            <div class="btn-group-sm" id="toolbar" role="group">
                <strong id="awardScore" style="color: red;"></strong><strong id="illegalScore" style="color: red;"></strong>
            </div>
            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        var editFlag = [[${@permission.hasPermi('school:illegalRecord:edit')}]];
        var removeFlag = [[${@permission.hasPermi('school:illegalRecord:remove')}]];
        var prefix = ctx + "student/illegalRecord";
        var statusDatas = [[${@dict.getType('sys_data_status')}]];
        $(function() {
            var options = {
                url: prefix + "/list",
                createUrl: prefix + "/add",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
                exportUrl: prefix + "/export",
                onLoadSuccess:calScore,
                modalName: "违规记录",
                columns: [
                {
                    field: 'id', 
                    title: 'null',
                    visible: false
                },
                {
                    field: 'studentName',
                    title: '学生'
                },
                {
                    field: 'gradeName',
                    title: '年级'
                },
                {
                    field: 'className',
                    title: '班级'
                },
                {
                    field: 'illegalTypeName',
                    title: '名称'
                },

                {
                    field: 'detail', 
                    title: '详情',
                    formatter: function(value, row, index) {
                        return $.table.tooltip(value);
                    }
                },
                {
                    field: 'createTime',
                    title: '创建时间'
                }]
            };
            $.table.init(options);
        });
        /**
         * 计算得分
         */
        function calScore() {

            var data =  $("#bootstrap-table").bootstrapTable("getData");
            if(data != null){

                var awardScore = 0;
                var illegalScore = 0;
                for (let i = 0; i < data.length; i++) {

                    if(data[i].type == 1){
                        awardScore = Number(awardScore)+Number(data[i].score);
                    }else {
                        illegalScore = Number(illegalScore) + Number(data[i].score);
                    }
                }
                $("#awardScore").text("奖励【"+awardScore+"】分");
                $("#illegalScore").text("处罚【"+illegalScore+"】分");
            }
        }
    </script>
</body>
</html>